package vn.allmobile.newsreader.customview;

import vn.allmobile.newsreader.utils.Log;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.ViewGroup;
import android.widget.GridView;

public class ExpandableHeightGridView extends GridView
{

    boolean expanded = false;

    public ExpandableHeightGridView(Context context)
    {
        super(context);
    }

    public ExpandableHeightGridView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }

    public ExpandableHeightGridView(Context context, AttributeSet attrs,
            int defStyle)
    {
        super(context, attrs, defStyle);
    }

    public boolean isExpanded()
    {
        return expanded;
    }

    @Override
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
    {
    	//Log.v("widthMeasureSpec:" +widthMeasureSpec + "heightMeasureSpec: "+ heightMeasureSpec);
    	int heightSpec;

        if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) {
            // The great Android "hackatlon", the love, the magic.
            // The two leftmost bits in the height measure spec have
            // a special meaning, hence we can't use them to describe height.
            heightSpec = MeasureSpec.makeMeasureSpec(
                    Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST);
        }
        else {
            // Any other height should be respected as is.
            heightSpec = heightMeasureSpec;
        }

        super.onMeasure(widthMeasureSpec, heightSpec);
    }

	/* (non-Javadoc)
	 * @see android.view.View#setOnTouchListener(android.view.View.OnTouchListener)
	 */
	@Override
	public void setOnTouchListener(OnTouchListener l) {
		// TODO Auto-generated method stub
		
		Log.v("grid view touch");
		super.setOnTouchListener(l);
	}
    
    
	@Override
	public boolean onTouchEvent(MotionEvent event) {
	    if( event.getAction()==MotionEvent.ACTION_UP){
	        //Log.d(TAG, "onTouchEvent:ACTION_UP");
	    	Log.v("ExpandableHeightGridView onTouchEvent:ACTION_UP");
	    	super.onTouchEvent(event);
	      //  return false;
	    }else if(event.getAction()==MotionEvent.ACTION_DOWN){
	        //Log.d(TAG, "onTouchEvent:ACTION_DOWN");
	    	Log.v("ExpandableHeightGridView onTouchEvent:ACTION_DOWN");
	    	super.onTouchEvent(event);
	        //return false;
	    }else{
	        //Log.d(TAG, "onTouchEvent:ACTION_UNKWON");
	        return super.onTouchEvent(event);
	    }
	    return true;
	}

 
}
